package com.hc.serviceimpl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hc.entity.DigitalSignature;
import com.hc.entity.QcEquipment;
import com.hc.entity.QcMonitor;
import com.hc.mapper.DigitalSignatureMapper;
import com.hc.mapper.QcEquipmentMapper;
import com.hc.model.QcRecordStatus;
import com.hc.model.QualityControlReport;
import com.hc.model.QualityControlReportList;
import com.hc.model.WorkbenchModel;
import com.hc.service.EquipmentRecordServiceImplUtilService;
import com.hc.util.UserInfoPost;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author LiuZhiHao
 * @date 2020/9/9 14:13
 * 描述:
 **/
@Service
public class EquipmentRecordServiceImplUtilServiceImpl implements EquipmentRecordServiceImplUtilService {
    @Autowired
    private UserInfoPost userInfoPost;
    @Autowired
    private QcEquipmentMapper qcEquipmentMapper;
    @Autowired
    private DigitalSignatureMapper digitalSignatureMapper;

    @Override
    public List<QcRecordStatus> inspectionStatus(List<QcRecordStatus> qcRecordStatuses) {
        //获取所有设备巡查情况
        //通过qcRecordStatuses集合对象获取以设备分类分组的map集合对象，键为设备分类ClassifyId，值为QcRecordStatus对象的属性ClassifyId与键相同的所有QcRecordStatus对象
        Map<String, List<QcRecordStatus>> collect = qcRecordStatuses.stream().collect(Collectors.groupingBy(QcRecordStatus::getClassifyId));
        //获取collect集合的所有键，封装到一个set集合中
        Set<String> keys = collect.keySet();
        //创建一个包含QcRecordStatus对象的list集合
        List<QcRecordStatus> qcRecordStatusess = new ArrayList<>();
        //遍历键集合
        keys.forEach(s -> {
            //创建一个QcRecordStatus对象
            QcRecordStatus qcRecordStatus = new QcRecordStatus();
            //给该对象设置设备名称
            qcRecordStatus.setEqName(s);
            //获取当前键对应的value值，值是一个QcRecordStatus对象集合
            List<QcRecordStatus> qcRecordStatuses1 = collect.get(s);
            //创建一个包含QcRecordStatus对象的集合
            List<QcRecordStatus> qcRecordStatuses2 = new ArrayList<>();
            //只拿每个设备最新的一条
            //将每个设备类型对应的集合里面的对象再按设备id分组转换成设备id为键，值为所有设备id与键相等的QcRecordStatus对象的map集合
            Map<Integer, List<QcRecordStatus>> collect2 = qcRecordStatuses1.stream().collect(Collectors.groupingBy(QcRecordStatus::getEqId));
            //获取上面操作的键集合
            Set<Integer> keySet = collect2.keySet();
            //遍历键集合
            keySet.forEach(o -> {
                //获取每个键对应的value值
                List<QcRecordStatus> list = collect2.get(o);
                int size = list.size();
                //如果当前value值的size小于2，即集合的大小小于2
                if (size < 2) {
                    //将集合里面的第一条数据添加进qcRecordStatuses2集合中
                    qcRecordStatuses2.add(list.get(0));
                    //如果当前value值的size大于等于2，即集合的大小大于等2
                } else {
                    //将list集合通过创建时间来排序
                    List<QcRecordStatus> collect1 = list.stream().sorted(Comparator.comparing(QcRecordStatus::getCreateTime)).collect(Collectors.toList());
                    //将最后一条数据添加到qcRecordStatuses2集合中，即创建时间是最后一个创建的对象，也就是最新的那一条数据
                    qcRecordStatuses2.add(collect1.get(collect1.size() - 1));
                }
            });
            //通过qcRecordStatuses2集合对象生成一个仅包含QcRecordStatus的Statuss属性的list集合
            List<String> collect1 = qcRecordStatuses2.stream().map(QcRecordStatus::getStatuss).collect(Collectors.toList());
            //如果collect1集合中包含n
            if (collect1.contains("n")) {
                //设置qcRecordStatus对象的IsCheck属性为false
                qcRecordStatus.setIsCheck(false);
                //如果collect1集合中不包含n
            } else {
                //设置qcRecordStatus对象的IsCheck属性为true
                qcRecordStatus.setIsCheck(true);
            }
            //遍历qcRecordStatuses2集合
            qcRecordStatuses2.forEach(m -> {
                //如果qcRecordStatuses2集合中每个下标的对象的Statuss属性等于n
                if (StringUtils.equals(m.getStatuss(), "n")) {
                    //将当前对象的IsCheck属性设置为false
                    m.setIsCheck(false);
                    //如果qcRecordStatuses2集合中每个下标的对象的Statuss属性不等于n
                } else {
                    //将当前对象的IsCheck属性设置为true
                    m.setIsCheck(true);
                    //设置qcRecordStatus对象的创建时间
                    qcRecordStatus.setCreateTime(m.getCreateTime());
                    //设置qcRecordStatus对象的创建人id
                    qcRecordStatus.setUserId(m.getUserId());
                }
            });
            //设置qcRecordStatus对象的QcRecordStatuses属性
            qcRecordStatus.setQcRecordStatuses(qcRecordStatuses2);
            //将qcRecordStatus对象添加到qcRecordStatusess集合中
            qcRecordStatusess.add(qcRecordStatus);

        });
        //过滤qcRecordStatuses集合中创建人id不为空的数据，然后将其转化成仅包含创建人id的set集合
        Set<String> collect1 = qcRecordStatuses.stream().filter(s -> StringUtils.isNotEmpty(s.getUserId())).map(QcRecordStatus::getUserId).collect(Collectors.toSet());
        //通过用户id获取用户名称
        Map<String, String> allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(collect1);
        //遍历qcRecordStatusess集合
        qcRecordStatusess.forEach(s -> {
            //获取当前下标对象的UserId属性的值
            String createBy = s.getUserId();
            //通过userId这个键获取allSysUserinfoByIds集合中对应的值
            String createName = allSysUserinfoByIds.get(createBy);
            //设置当前对象的UserName属性
            s.setUserName(createName);
            //获取当前对象的QcRecordStatuses属性值
            List<QcRecordStatus> qcRecordStatuses1 = s.getQcRecordStatuses();
            //通过qcRecordStatuses1集合过滤出所有创建时间不为空的数据，然后根据创建时间排序，转化成一个新的list集合
            List<QcRecordStatus> collect2 = qcRecordStatuses1.stream().filter(l -> null != l.getCreateTime()).sorted(Comparator.comparing(QcRecordStatus::getCreateTime)).collect(Collectors.toList());
            //如果qcRecordStatuses1集合不为空
            if (CollectionUtils.isNotEmpty(qcRecordStatuses1)) {
                //遍历该集合
                qcRecordStatuses1.forEach(h -> {
                    //获取该集合每个下标对象的UserId属性的值
                    String userId = h.getUserId();
                    //设置当前对象的UserName属性
                    h.setUserName(allSysUserinfoByIds.get(userId));
                });
            }
            //如果collect2集合的大小大于1
            if (collect2.size() > 1) {
                //设置qcRecordStatusess集合中当前下标位置对象的创建时间属性，设置的是创建时间是最大的对象
                s.setCreateTime(collect2.get(collect2.size() - 1).getCreateTime());
            }
        });
        return qcRecordStatusess;
    }

    @Override
    public List<QcRecordStatus> workStatus(List<QcRecordStatus> qcRecordStatusesa, List<QcRecordStatus> qcRecordStatusesb) {
        List<QcRecordStatus> list = new ArrayList<>();
        //通过qcRecordStatusesa集合获取有设备id为键，值为所有QcRecordStatus对象的设备id与键相同的对象集合（上班）
        Map<Integer, List<QcRecordStatus>> collecta = qcRecordStatusesa.stream().collect(Collectors.groupingBy(QcRecordStatus::getEqId));
        //通过qcRecordStatusesa集合获取有设备id为键，值为所有QcRecordStatus对象的设备id与键相同的对象集合（下班）
        Map<Integer, List<QcRecordStatus>> collectb = qcRecordStatusesb.stream().collect(Collectors.groupingBy(QcRecordStatus::getEqId));
        //获取collecta集合的所有键
        Set<Integer> keysa = collecta.keySet();
        //遍历键集合
        keysa.forEach(s -> {
            //操作前
            //获取当前键对应的List<QcRecordStatus>集合对象（上班）
            List<QcRecordStatus> qcRecordStatusesa1 = collecta.get(s);
            //操作后
            //获取当前键对应的List<QcRecordStatus>集合对象（下班）
            List<QcRecordStatus> qcRecordStatusesb1 = collectb.get(s);
            //遍历qcRecordStatusesa1集合
            qcRecordStatusesa1.forEach(m -> {
                //获取QcRecordStatus对象的WorkbenchOperationBatch属性
                String workbenchOperationBatch = m.getWorkbenchOperationBatch();
                //如果workbenchOperationBatch不为空
                if (StringUtils.isNotEmpty(workbenchOperationBatch)) {
                    //设置QcRecordStatus对象的WorkBefore属性为true
                    m.setWorkBefore(true);
                    //如果qcRecordStatusesb1集合为空
                    if (CollectionUtils.isEmpty(qcRecordStatusesb1)) {
                        //设置QcRecordStatus对象的WorkAfter属性为false
                        m.setWorkAfter(false);
                        //将WorkAfter属性为false的对象添加到list集合中
                        list.add(m);
                        return;
                    }
                    //如果qcRecordStatusesb1集合不为空，通过qcRecordStatusesb1集合获取一个仅包含WorkbenchOperationBatch属性的set集合
                    Set<String> collect = qcRecordStatusesb1.stream().map(QcRecordStatus::getWorkbenchOperationBatch).collect(Collectors.toSet());
                    //如果collect集合中包含workbenchOperationBatch
                    if (collect.contains(workbenchOperationBatch)) {
                        //将qcRecordStatusesb1集合过滤成QcRecordStatus对象的WorkbenchOperationBatch属性的值等于上班集合状态中的workbenchOperationBatch的值的数据，并取其中的第一条数据
                        QcRecordStatus qcRecordStatus = qcRecordStatusesb1.stream().filter(o -> o.getWorkbenchOperationBatch().equals(workbenchOperationBatch)).collect(Collectors.toList()).stream().findFirst().get();
                        //设置当前对象的WorkAfter属性为true
                        m.setWorkAfter(true);
                        //设置当前对象的AfterCreateTime属性
                        m.setAfterCreateTime(qcRecordStatus.getCreateTime());
                        //如果collect集合中不包含workbenchOperationBatch
                    } else {
                        //设置当前对象的WorkAfter属性为false
                        m.setWorkAfter(false);
                    }
                    //如果workbenchOperationBatch不为空
                } else {
                    //设置当前对象的WorkBefore属性为false
                    m.setWorkBefore(false);
                    //设置当前对象的WorkAfter属性为false
                    m.setWorkAfter(false);
                }
                //将当前对象添加到list集合中
                list.add(m);
            });
        });
        //通过list集合获取一个仅包含UserId属性的set集合
        Set<String> collect = list.stream().map(QcRecordStatus::getUserId).collect(Collectors.toSet());
        //通过用户id获取用户名称
        Map<String, String> allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(collect);
        //遍历list集合
        list.forEach(s -> {
            //获取当前对象的UserId值
            String createBy = s.getUserId();
            //获取userId对象的value值，即创建人的姓名
            String createName = allSysUserinfoByIds.get(createBy);
            //设置当前对象的UserName属性
            s.setUserName(createName);
        });
        //返回该list集合
        return list;
    }

    @Override
    public void setWorkbenchModelUserName(List<WorkbenchModel> listResult) {
        Set<String> ids = new HashSet<>();
        listResult.forEach(r -> {
            ids.add(r.getCheckingPeopleBegin());
            ids.add(r.getCheckingPeopleEnd());
        });
        Map<String, String> allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(ids);
        listResult.forEach(l -> {
            l.setCheckingPeopleNameBegin(allSysUserinfoByIds.get(l.getCheckingPeopleBegin()));
            l.setCheckingPeopleNameEnd(allSysUserinfoByIds.get(l.getCheckingPeopleEnd()));
        });
    }

    @Override
    public Map<Integer, String> getEqNameMap(List<Integer> eqIds) {
        List<QcEquipment> qcEquipments = qcEquipmentMapper.selectBatchIds(eqIds);
        Map<Integer, List<QcEquipment>> map = qcEquipments.stream().collect(Collectors.groupingBy(QcEquipment::getId));
        Set<Integer> key = map.keySet();
        Map<Integer, String> map1 = new HashMap<>();
        key.forEach(k -> {
            List<QcEquipment> qcEquipments1 = map.get(k);
            String deviceName = qcEquipments1.get(0).getDeviceName();
            map1.put(k, deviceName);
        });
        return map1;
    }

    @Override
    public List<QualityControlReportList> setQualityControlReportUserName(List<QualityControlReportList> collecter) {
        Set<String> ids = new HashSet<>();
        collecter.forEach(c -> {
            List<QualityControlReport> qcrs = c.getQcrs();
            qcrs.forEach(q -> {
                ids.add(q.getCheckingPeopleOnWork());
                ids.add(q.getCheckingPeopleOffWork());
            });
        });
        Map<String, String> allSysUserinfoByIds = userInfoPost.getAllSysUserinfoByIds(ids);
        collecter.forEach(c -> {
            List<QualityControlReport> qcrs = c.getQcrs();
            qcrs.forEach(q -> {
                q.setCheckingPeopleNameOnWork(allSysUserinfoByIds.get(q.getCheckingPeopleOnWork()));
                q.setCheckingPeopleNameOffWork(allSysUserinfoByIds.get(q.getCheckingPeopleOffWork()));
            });
        });
        return collecter;
    }

    @Override
    public void setDigitalSignatureAttribute(List<QualityControlReportList> collecter) {
        List<QualityControlReport> qualityControlReports = new ArrayList<>();
        collecter.forEach(s->{
            List<QualityControlReport> qcrs = s.getQcrs();
            qualityControlReports.addAll(qcrs);
        });
        Map<String, List<DigitalSignature>> idWordMap = null;
        if (CollectionUtils.isNotEmpty(qualityControlReports)){
            List<String> idOnWorks = qualityControlReports.stream().filter(QualityControlReport->null!=QualityControlReport.getIdOnWork())
                    .map(QualityControlReport::getIdOnWork).collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(idOnWorks)){
                List<DigitalSignature> digitalSignatures = digitalSignatureMapper.selectList(Wrappers.lambdaQuery(new DigitalSignature()).in(DigitalSignature::getWorkOnRecordId, idOnWorks));
                idWordMap = digitalSignatures.stream().collect(Collectors.groupingBy(DigitalSignature::getWorkOnRecordId));
            }
        }
        //遍历拼装的巡检记录集合
        for (int i = 0; i < collecter.size(); i++) {
            //获取每个下标的巡检记录
            QualityControlReportList reportList = collecter.get(i);
            //获取每个下标的QualityControlReport数据集合，即上班巡检和下班巡检的数据
            List<QualityControlReport> qcrs = reportList.getQcrs();
            List<Map<String, String>> mapList = new ArrayList<>();
            qcrs.forEach(q -> {
                //获取上班巡检记录的id
                String idOnWork = q.getIdOnWork();
                //如果上班巡检id不为null，将上班巡检的id添加到map集合中，list集合再将map集合添加进去
                if (idOnWork != null) {
                    Map<String, String> map1 = new HashMap<>();
                    map1.put("idOnWork", idOnWork);
                    mapList.add(map1);
                }
            });

            //如果封装map集合的list集合不为null
            if (CollectionUtils.isNotEmpty(mapList)) {
                //获取最后一条带上班巡检记录id的map集合
                Map<String, String> stringLongMap = mapList.get(mapList.size() - 1);
                //获取上班巡检记录id
                String idWorkStringValue = stringLongMap.get("idOnWork");
                //通过上班巡检记录id获取对应的签章记录数据
                //DigitalSignature isSignature = digitalSignatureMapper.getIsSignature(idOnWork);
                if (null!=idWordMap&&!idWordMap.isEmpty()){
                    List<DigitalSignature> digitalSignatures = idWordMap.get(idWorkStringValue);
                    if (CollectionUtils.isNotEmpty(digitalSignatures)){
                        DigitalSignature isSignature = digitalSignatures.get(0);
                        //如果获取的签章记录不为null，设置对应的签章记录属性值
                        if (isSignature != null) {
                            reportList.setSignatureId(isSignature.getSignatureId());
                            reportList.setIsSignature(isSignature.getIsSignature());
                            reportList.setSelfCheck(isSignature.getSelfCheck());
                            reportList.setChecker(isSignature.getChecker());
                        }
                    }

                }
            }
        }
    }

    @Override
    public void setRecordInPYX(int eqId, String date, QualityControlReportList qualityControlReportList, Map<Integer, List<QcMonitor>> qcMonitorsMap, Map<String, List<QcMonitor>> qcMonitorsMap2, String type, Map<String, String> allSysUserinfoByIds) {
        List<QcMonitor> qcMonitors = null;
        //判断是用于获取月数据还是日数据
        if (StringUtils.equals("day", type) && qcMonitorsMap != null) {
            qcMonitors = qcMonitorsMap.get(eqId);
        } else if (StringUtils.equals("month", type) && qcMonitorsMap2 != null) {
            qcMonitors = qcMonitorsMap2.get(date);
        }
        //如果对应的设备在当天有维护记录
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            StringBuffer sb = new StringBuffer();
            List<Long> ids = new ArrayList<>();
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
            qcMonitors.forEach(q -> {
                Long id = q.getId();
                ids.add(id);
                String maintenanceProjectsId = q.getMaintenanceProjects();
                String remark = q.getRemark();
                //判断对应维护记录属于培养箱的CODA更换还是常规维护
                if (StringUtils.isNotEmpty(maintenanceProjectsId)) {
                    //获取维护记录的保养时间
                    Date maintainTime = q.getMaintainTime();
                    String maintainTimeStr = sdf2.format(maintainTime);
                    String createBy = q.getCreateBy();
                    String createName = allSysUserinfoByIds.get(createBy);
                    String maintenanceProjects = null;
                    if (StringUtils.equals("1", maintenanceProjectsId)) {
                        maintenanceProjects = "清洁";
                    } else if (StringUtils.equals("2", maintenanceProjectsId)) {
                        maintenanceProjects = "定期保养";
                    } else if (StringUtils.equals("3", maintenanceProjectsId)) {
                        maintenanceProjects = "更换耗材";
                    } else if (StringUtils.equals("4", maintenanceProjectsId)) {
                        maintenanceProjects = "故障维修";
                    } else if (StringUtils.equals("5", maintenanceProjectsId)) {
                        maintenanceProjects = "加水";
                    }
                    sb.append("维护项目：" + maintenanceProjects + "，").append("保养时间：" + maintainTimeStr + "，")
                            .append("维护人：" + createName);
                    if (StringUtils.isNotEmpty(remark)) {
                        sb.append("，备注：" + remark);
                    }
                    sb.append(";");
                } else {
                    //获取维护记录的创建时间
                    Date createTime = q.getCreateTime();
                    String createTimeStr = sdf2.format(createTime);
                    String createName = allSysUserinfoByIds.get(q.getCreateBy());
                    String commonlyUsed = q.getCommonlyUsed();
                    //表示是培养箱CODA更换
                    if (StringUtils.equals("5", commonlyUsed)) {
                        sb.append("维护类型：培养箱CODA更换，").append("维护时间：" + createTimeStr + "，")
                                .append("维护人：" + createName);
                        sb.append(";");
                    }
                }
            });
            String str = sb.toString();
            qualityControlReportList.setMaintenanceRecord(str);
            qualityControlReportList.setQcMonitorIds(ids);
        }
    }

    @Override
    public void setRecordInXWJ(int eqId, String date, QualityControlReportList qualityControlReportList, Map<Integer, List<QcMonitor>> qcMonitorsMap, Map<String, List<QcMonitor>> qcMonitorsMap2, String type, Map<String, String> allSysUserinfoByIds) {
        List<QcMonitor> qcMonitors = null;
        //判断是用于获取月数据还是日数据
        if (StringUtils.equals("day", type) && qcMonitorsMap != null) {
            qcMonitors = qcMonitorsMap.get(eqId);
        } else if (StringUtils.equals("month", type) && qcMonitorsMap2 != null) {
            qcMonitors = qcMonitorsMap2.get(date);
        }
        //如果对应的设备在当天有维护记录
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            StringBuffer sb = new StringBuffer();
            List<Long> ids = new ArrayList<>();
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
            qcMonitors.forEach(q -> {
                Long id = q.getId();
                ids.add(id);
                String maintenanceProjectsId = q.getMaintenanceProjects();
                String remark = q.getRemark();
                //判断对应设备属于倒置显微镜还是常规显微镜
                if (StringUtils.isNotEmpty(maintenanceProjectsId)) {
                    //获取维护记录的保养时间
                    Date maintainTime = q.getMaintainTime();
                    String maintainTimeStr = sdf2.format(maintainTime);
                    String createBy = q.getCreateBy();
                    String createName = allSysUserinfoByIds.get(createBy);
                    String maintenanceProjects = null;
                    if (StringUtils.equals("1", maintenanceProjectsId)) {
                        maintenanceProjects = "清洁";
                    } else if (StringUtils.equals("2", maintenanceProjectsId)) {
                        maintenanceProjects = "定期保养";
                    } else if (StringUtils.equals("3", maintenanceProjectsId)) {
                        maintenanceProjects = "更换耗材";
                    } else if (StringUtils.equals("4", maintenanceProjectsId)) {
                        maintenanceProjects = "故障维修";
                    } else if (StringUtils.equals("5", maintenanceProjectsId)) {
                        maintenanceProjects = "加水";
                    }
                    sb.append("维护项目：" + maintenanceProjects + "，").append("保养时间：" + maintainTimeStr + "，")
                            .append("维护人：" + createName);
                    if (StringUtils.isNotEmpty(remark)) {
                        sb.append("，备注：" + remark);
                    }
                    sb.append(";");
                } else {
                    Date nextCalibrationTime = q.getNextCalibrationTime();
                    String nextCalibrationTimeStr = sdf2.format(nextCalibrationTime);
                    Date createTime = q.getCreateTime();
                    String createTimeStr = sdf2.format(createTime);
                    String createName = allSysUserinfoByIds.get(q.getCreateBy());
                    String stmMonitorTypeId = q.getStmMonitorType();
                    String getStmMonitorType = null;
                    String isCalibrationId = q.getIsCalibration();
                    String IsCalibration = null;
                    if (StringUtils.equals("1", stmMonitorTypeId)) {
                        getStmMonitorType = "恒温板";
                        if (StringUtils.equals("1", isCalibrationId)) {
                            //获取维护项目的项目Id
                            IsCalibration = "已校准";
                        } else if (StringUtils.equals("2", isCalibrationId)) {
                            IsCalibration = "未校准";
                        }
                    } else if (StringUtils.equals("2", stmMonitorTypeId)) {
                        getStmMonitorType = "激光";
                        if (StringUtils.equals("1", isCalibrationId)) {
                            //获取维护项目的项目Id
                            IsCalibration = "已校准";
                        } else if (StringUtils.equals("2", isCalibrationId)) {
                            IsCalibration = "未校准";
                        }
                    }
                    sb.append("监测类型：" + getStmMonitorType + "，").append("是否校准：" + IsCalibration + "，")
                            .append("维护时间：" + createTimeStr + "，")
                            .append("下次校准时间：" + nextCalibrationTimeStr + "，")
                            .append("维护人：" + createName);
                    if (StringUtils.isNotEmpty(remark)) {
                        sb.append("，备注：" + remark);
                    }
                    sb.append(";");
                }
            });
            String str = sb.toString();
            qualityControlReportList.setMaintenanceRecord(str);
            qualityControlReportList.setQcMonitorIds(ids);
        }
    }

    @Override
    public void setRecord(int eqId, String date, QualityControlReportList qualityControlReportList, Map<Integer, List<QcMonitor>> qcMonitorsMap, Map<String, List<QcMonitor>> qcMonitorsMap2, String type, Map<String, String> allSysUserinfoByIds) {
        List<QcMonitor> qcMonitors = null;
        //判断是用于获取月数据还是日数据
        if (StringUtils.equals("day", type) && qcMonitorsMap != null) {
            qcMonitors = qcMonitorsMap.get(eqId);
        } else if (StringUtils.equals("month", type) && qcMonitorsMap2 != null) {
            qcMonitors = qcMonitorsMap2.get(date);
        }
        //如果对应的设备在当天有维护记录
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            //创建一个集合用来装是否添加液氮的维护记录，
            // 只有胚胎库对应的设备才有是否添加液氮的属性值，设置就有，没有设置不会有这样的一条维护记录
            //其他设备都没有这样的维护记录，其他设置的维护记录的是否添加液氮的属性值都为null
            List<QcMonitor> isAddLiquidNitrogens = new ArrayList<>();
            //创建一个封装没有添加页面属性值的维护记录的集合对象
            List<QcMonitor> qcMonitorsCopy = new ArrayList<>();
            for (int i = 0; i < qcMonitors.size(); i++) {
                //获取当前维护记录对象里面是否添加液氮的属性值是否为null
                String isAddLiquidNitrogen = qcMonitors.get(i).getIsAddLiquidNitrogen();
                //不为null则将该维护记录添加到isAddLiquidNitrogens集合中，将原始在qcMonitors集合中的该条记录移除
                if (StringUtils.isNotEmpty(isAddLiquidNitrogen)) {
                    isAddLiquidNitrogens.add(qcMonitors.get(i));
                    //将常规的维护记录添加到qcMonitorsCopy集合中
                }else {
                    qcMonitorsCopy.add(qcMonitors.get(i));
                }
            }
            //判断isAddLiquidNitrogens集合是否为null，不为null则将qualityControlReportList对象的是否添加液氮的属性值设置为该集合中任意一个元素的是否添加液氮的属性值
            if (CollectionUtils.isNotEmpty(isAddLiquidNitrogens)) {
                String isAddLiquidNitrogen = isAddLiquidNitrogens.get(0).getIsAddLiquidNitrogen();
                qualityControlReportList.setIsAddLiquidNitrogen(isAddLiquidNitrogen);
            } else {
                //是否添加液氮设置为否
                qualityControlReportList.setIsAddLiquidNitrogen("0");
            }
            //如果移除是否添加液氮的维护记录之后的qcMonitors集合不为null
            if (CollectionUtils.isNotEmpty(qcMonitorsCopy)) {
                //接下来做维护记录属性拼接操作
                SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                //用于之后所有的维护记录属性拼接
                StringBuffer sb = new StringBuffer();
                int size = qcMonitorsCopy.size();
                List<Long> ids = new ArrayList<>();
                for (int j = 0; j < size; j++) {
                    Long id = qcMonitorsCopy.get(j).getId();
                    ids.add(id);
                    //获取维护记录的备注
                    String remark = qcMonitorsCopy.get(j).getRemark();
                    //获取维护记录的操作人id
                    String createBy = qcMonitorsCopy.get(j).getCreateBy();
                    //通过操作人id获取操作人姓名
                    String createName = allSysUserinfoByIds.get(createBy);
                    //获取维护记录的保养时间
                    Date maintainTime = qcMonitorsCopy.get(j).getMaintainTime();
                    String maintainTimeStr = sdf2.format(maintainTime);
                    //获取维护记录的维护项目id
                    String maintenanceProjectsId = qcMonitorsCopy.get(j).getMaintenanceProjects();
                    String maintenanceProjects = null;
                    if (StringUtils.equals("1", maintenanceProjectsId)) {
                        maintenanceProjects = "清洁";
                    } else if (StringUtils.equals("2", maintenanceProjectsId)) {
                        maintenanceProjects = "定期保养";
                    } else if (StringUtils.equals("3", maintenanceProjectsId)) {
                        maintenanceProjects = "更换耗材";
                    } else if (StringUtils.equals("4", maintenanceProjectsId)) {
                        maintenanceProjects = "故障维修";
                    } else if (StringUtils.equals("5", maintenanceProjectsId)) {
                        maintenanceProjects = "加水";
                    }
                    sb.append("维护项目：" + maintenanceProjects + "，").append("保养时间：" + maintainTimeStr + "，")
                            .append("维护人：" + createName);
                    if (StringUtils.isNotEmpty(remark)) {
                        sb.append("，备注：" + remark);
                        sb.append(";");
                    }
                }
                String str = sb.toString();
                qualityControlReportList.setMaintenanceRecord(str);
                qualityControlReportList.setQcMonitorIds(ids);
            }
        }
    }

    @Override
    public void setRecordForHJ(int eqId, String date, QualityControlReportList qualityControlReportList, Map<Integer, List<QcMonitor>> qcMonitorsMap, Map<String, List<QcMonitor>> qcMonitorsMap2, String type, Map<String, String> allSysUserinfoByIds) {
        List<QcMonitor> qcMonitors = null;
        //判断是用于获取月数据还是日数据
        if (StringUtils.equals("day", type) && qcMonitorsMap != null) {
            qcMonitors = qcMonitorsMap.get(eqId);
        } else if (StringUtils.equals("month", type) && qcMonitorsMap2 != null) {
            qcMonitors = qcMonitorsMap2.get(date);
        }
        //如果对应的设备在当天有维护记录
        if (CollectionUtils.isNotEmpty(qcMonitors)) {
            //用于之后所有的维护记录属性拼接
            StringBuffer sb = new StringBuffer();
            int size = qcMonitors.size();
            List<Long> ids = new ArrayList<>();
            qcMonitors.forEach(q -> {
                Long id = q.getId();
                ids.add(id);
                //获取维护记录的保养时间
                Date maintainTime = q.getCreateTime();
                SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String maintainTimeStr = sdf2.format(maintainTime);
                String createName = allSysUserinfoByIds.get(q.getCreateBy());
                sb.append("已更换回风滤网：是，").append("保养时间：" + maintainTimeStr + "，")
                        .append("维护人：" + createName);
                sb.append(";");
            });
            String str = sb.toString();
            qualityControlReportList.setMaintenanceRecord(str);
            qualityControlReportList.setQcMonitorIds(ids);
        }
    }



}
